package com.demoworld;

/**
 * Created by francis on 2017/7/5.
 */
public class JArrayStack implements IStack {
    private int[] arr;
    private int tailIndex;//当前栈的尾巴索引， 这个位置是最后一个数据
    private int maxLength;

    public JArrayStack(int maxLength) {
        this.maxLength = maxLength;
        arr = new int[this.maxLength];
        tailIndex = -1;
    }


    @Override
    public void push(int n) {
        if (tailIndex + 1 >= arr.length) {
//            System.out.println("warn: queue is full");
            return;
        }
        tailIndex++;
        arr[tailIndex] = n;
    }

    @Override
    public int pop() {
        int result = arr[tailIndex];
        tailIndex--;
        return result;
    }

    @Override
    public boolean isEmpty() {
        return tailIndex == -1;
    }
}
